﻿@model BookingHotelModel
@{
	ViewBag.Title = Resources.HotelTrafficBook + ConstValues.strDash + ViewBag.ConferenceName;
}
<div class="rbox fl" style="width:1200px">
	<div id="right">
		<div class="con">
			<div class="formDiv">
				<form id="frmForm" method="post" enctype="">
					@Html.AntiForgeryToken()
					<span id="ctnForm"></span>
					<input type="hidden" id="hidConferenceId" name="ConferenceId" />
					<input type="hidden" id="hidCurrency" name="Currency" />
					<input type="hidden" id="hidIsBenefit" name="IsBenefit" />
					<input type="hidden" id="hidHotelCount" name="HotelCount" value="-1"/>
					<input type="hidden" id="hidTrafficCount" name="TrafficCount" value="-1"/>
				</form>
			</div>
			<div id="hotelBooking">
				<div class="tit01" ><span style="font-weight:bold;">@Resources.HotelBooking</span></div>
				<div>
					<form id="hotelForm" >
						<div id="booking">
							<div class="clear"></div>
						</div>						
						<div class="clear"></div>
						<div style="width:30%;text-align:right;float:left;margin-top:30px">
							<input type="button" id="hotelContinueBtn" class="abtn" onclick="hotelContinueBooking();" value="@Resources.ContinueBooking">					
						</div>
						<div style="margin-top:30px">
							<input style="margin-left:15px;" type="button" id="hotelCancelBtn" class="rbtn" onclick="hotelCancelBooking();" value="@Resources.Cancel" />
						</div>
						<div class="clear"></div>
						<div style="padding: 10px 0; text-align: right;width:27%;float:left">
							<span>@Resources.Contact：</span>
						</div>
						<div style="padding: 10px 0; text-align: left;">
							<input id="contactName" name="contactName" class="easyui-textbox" style="height:27px; width:13%;" data-options="required:true">
							<span style="margin-left:10px;display:inline-block; width:60px;">@Resources.Mobile：</span><input id="contactMobile" name="contactMobile" class="easyui-numberbox" style="height:27px; width:13%;" data-options="required:true,min:0,precision:0">
							<span style="margin-left:10px;display:inline-block; width:60px;">@Resources.Mail：</span><input id="contactMail" name="contactMail" class="easyui-textbox" style="height:27px; width:13%;" data-options="required:true,validType:['email','length[1,100]']">
						</div>
						<div class="clear"></div>
						<div style="text-align: right;width:27%;float:left">
							<span>@Resources.Remark：</span>
						</div>
						<div style="text-align: left;">
							<input id="hotelRemark" name="hotelRemark" class="easyui-textbox" style="height:50px; width:616px;" data-options="multiline:true,validType:['length[1,1000]']">
						</div>
						<div class="clear"></div>
						<div style="width:27%; text-align: right;margin-top:10px;float:left;font-weight:bold">
							<span>@Resources.TotalFee：</span>
						</div>
						<div style="margin-top:10px;font-weight:bold">
							<span id="hotelTotalFee"></span>
						</div>
						<div class="clear"></div>
						<div style="display:inline-block;width:100%;">
							<div style="margin-top:10px; display:inline-block; float:left; text-align: right; width:27%; ">
								<span>@Resources.ImportantReminding：</span>
							</div>
							<div style="margin-top:10px; display:inline-block; float:left; text-align: left; width:620px;" id="checkHint"></div>
						</div>
						<div style="padding: 25px 0; text-align: center;">
							<input type="button" class="gbtn" onclick="doHotelBooking();" value="@Resources.Submit"/>&nbsp;&nbsp;
							<input type="button" id="hotelBookingBtn" class="lbtn" onclick="goTrafficBooking();" value="@Resources.GoTraffic" />
						</div>
					</form>
				</div>
			</div>
			<div id="trafficBooking">
				<div class="tit01" ><span style="font-weight:bold;">@Resources.TrafficService</span></div>
				<div>
					<form id="trafficForm" method="post">
						@Html.AntiForgeryToken()
						<div id="trafficDiv"></div>
					</form>
					<form id="trafficContactForm">
						<table style="margin-bottom: 30px;width:800px;margin:0 auto">
							<tr>
								<td rowspan="7" style="width:13px;padding-top:40px"></td>
								<td style="padding-left :30px;padding-top:40px;">
									<input type="button" id="trafficContinueBtn" class="abtn" onclick="trafficContinueBooking();" value="@Resources.ContinueBooking">
									<input style="margin-left:15px;" type="button" id="trafficCancelBtn" class="rbtn" onclick="trafficCancelBooking();" value="@Resources.Cancel" />
								</td>
							</tr>
							<tr >
								<td style="padding-left :30px;padding-top:10px;font-weight:bold"> @Resources.TotalFee：<span id="trafficTotalFee"></span></td>
							</tr>
							<tr >
								<td style="padding-left :30px;padding-top:10px;"> @Resources.Contact：<input id="trafficContactName" name="trafficContactName" class="easyui-textbox" style="height:27px; width:180px;margin-right" data-options="required:true">
									<span style="margin-left:10px">@Resources.Mobile：</span><input id="trafficContactMobile" name="trafficContactMobile" class="easyui-numberbox" style="height:27px; width:180px;" data-options="required:true,min:0,precision:0">
									<span style="margin-left:10px">@Resources.Mail：</span><input id="trafficContactMail" name="trafficContactMail" class="easyui-textbox" style="height:27px; width:180px;" data-options="required:true,validType:['email','length[1,100]']">
								</td>
							</tr>
							<tr>
								<td style="padding-left :30px;padding-top:10px;height:55px" valign="top" >
									<span>@Resources.Remark：</span><input id="trafficRemark" name="trafficRemark" class="easyui-textbox" style="height:50px; width:665px;" data-options="multiline:true,validType:['length[1,1000]']">
								</td>
							</tr>
							<tr>
								<td style="padding-left :30px;padding-top:10px;">
									<div style="display:inline-block;width:100%;">
										<div style="margin-top:10px; display:inline-block; float:left; text-align: right; ">
											<span>@Resources.ImportantReminding：</span>
										</div>
										<div style="margin-top:10px; display:inline-block; float:left; text-align: left; width:640px;" id="trafficHint"></div>
									</div>
								</td>
							</tr>
						</table>
					</form>	
					<div class="clear"></div>
					<div style="padding: 25px 0; text-align: center;margin:0 auto">
						<input type="button" class="gbtn" onclick="doTrafficBooking();" value="@Resources.Submit"/>&nbsp;&nbsp;
						<input type="button" id="hotelTrafficBtn" class="lbtn" onclick="goHotelBooking();" value="@Resources.GoHotel" />
					</div>					
				</div>
			</div>
		</div>
	</div>
</div>
<div id="currencyWindow" class="easyui-window"
	title="@Resources.ChooseCurrency" data-options="modal:true,closed:true,collapsible:false,minimizable:false,maximizable:false,resizable:false,closable:false,iconCls:'icon-save'"
	style="width:450px; height:150px; display:none;">
	<div class="popupDiv">
		<form id="chooseCurrencyForm"  >
			<select id="ddlCurrency" name="Currency" class="easyui-combobox" style="height:27px; width:300px;" data-options="editable:false,required:true,panelHeight:'auto'"></select>
		</form>		
		<div class="buttonDiv">
			<input type="button" class="btn lbtn" onclick="selectCurrency();" value="@Resources.Confirm" />&nbsp;&nbsp;
			<input type="button" class="btn rbtn" onclick="goBack()" value="@Resources.Cancel" />
		</div>
	</div>
</div>

@section Scripts {
<script>
	$(function () {
		$("#trafficBooking").hide()
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#hidIsBenefit").val("@Model.IsBenefit");
		$("#checkHint").append("@Html.Raw(Model.CheckHint.Replace("\"", "'"))");
		$("#trafficHint").append("@Html.Raw(Model.CheckHint.Replace("\"", "'"))");
		@*$("span[id='checkHint']").append("@Html.Raw(Model.CheckHint)")
		$("span[id='trafficHint']").append("@Html.Raw(Model.CheckHint)")*@

		if ("@Model.CurrencyCount" == 1) {
			if ("@Model.Currency" == "&#165;") {
				$("#hidCurrency").val("¥")
			} else {
				$("#hidCurrency").val("$")
			}
		} else {
			$("#currencyWindow").window("open");
		}

		hotelContinueBooking();
		trafficContinueBooking();
		$("#hotelCancelBtn").hide();
		$("#trafficCancelBtn").hide();

		$("#ddlCurrency").combobox({
			url: "@Url.Action(nameof(MeetingBookingController.GetCurrency),
					nameof(MeetingBookingController).GetControllerName())?conferenceId=" + "@Model.ConferenceId",
			valueField: "currency",
			textField: "currency",
			required: true,
			editable: false,
			panelHeight: "auto",
		});

		if ("@Model.HasHotel" == "True" && "@Model.HasTraffic" == "False") {
			$("#hotelBookingBtn").hide();
			$("#hotelBookingBtn").attr("disabled", "true");
		} else if ("@Model.HasHotel" == "False" && "@Model.HasTraffic" == "True") {
			$("#hotelTrafficBtn").hide();
			$("#hotelTrafficBtn").attr("disabled", "true");
			goTrafficBooking()
		}

		$("#contactName").textbox("setValue", "@Model.FullName");
		$("#contactMobile").textbox("setValue", "@Model.Mobile");
		$("#contactMail").textbox("setValue", "@Model.Mail");
		$("#trafficContactName").textbox("setValue", "@Model.FullName");
		$("#trafficContactMobile").textbox("setValue", "@Model.Mobile");
		$("#trafficContactMail").textbox("setValue", "@Model.Mail");
	});

	function doHotelBooking() {
		var isValid = $("#hotelForm").form("validate");
		var temp = parseInt($("#hidHotelCount").val());
		if (isValid && $("#name"+temp+"_0_1").textbox("getValue") != "") {
			var totalList = [];
			for (var i = 0; i <= temp; i++) {
				var roomNumber = $("#roomNumber" + i).numberbox("getValue");
				var checkInNumber = $("#checkInNumber" + i).numberbox("getValue");
				if (parseInt(checkInNumber) > parseInt(roomNumber) * 2) {
					common.showError("@Resources.MsgTooMuchCheckin");
					return;
				}
				var hotalMap = {};
				var nameList = [];
				var fillText = 0;
				for (var j = 0; j < parseInt(roomNumber) ; j++) {
					var list = [];
					list.push($("#name" + i + "_" + j + "_1").textbox("getValue"));
					list.push($("#name" + i + "_" + j + "_2").textbox("getValue"));
					nameList.push(list)
					if ($("#name" + i + "_" + j + "_1").textbox("getValue") != "") {
						fillText += 1;
					}
					if ($("#name" + i + "_" + j + "_2").textbox("getValue") != "") {
						fillText += 1;
					}
				}
				if (fillText != checkInNumber) {
					common.showError("@Resources.MsgEqualNumber");
					return;
				}
				hotalMap.nameList = nameList;
				hotalMap.hotelId = $("#hotel" + i).combobox("getValue");
				hotalMap.roomTypeId = $("#roomType" + i).combobox("getValue");
				hotalMap.price = $("#roomPrice" + i).html();
				hotalMap.checkinDate = $("#checkinDate" + i).combobox("getValue");
				hotalMap.checkoutDate = $("#checkoutDate" + i).combobox("getValue");

				if ($("#checkinDate" + i).combobox("getValue") >= $("#checkoutDate" + i).combobox("getValue")) {
					common.showError("@Resources.MsgChooseRightDate");
					return;
				}
				hotalMap.roomNumber = roomNumber;
				hotalMap.checkinNumber = checkInNumber;
				hotalMap.needCombine = document.getElementById("needCombine" + i).checked
				hotalMap.contactName = $("#contactName").textbox("getValue");
				hotalMap.contactMail = $("#contactMail").textbox("getValue");
				hotalMap.contactMobile = $("#contactMobile").numberbox("getValue");
				hotalMap.remark = $("#hotelRemark").textbox("getValue");
				hotalMap.currency = $("#hidCurrency").val();
				hotalMap.conferenceId = $("#hidConferenceId").val();
				hotalMap.totalFee = $("#hotelTotalFee").html();
				totalList.push(hotalMap);
			};
			var loading = layer.load(0, {
				shade: [0.4, "#fff"]
			});
			var token = $("#frmForm").find("input[name='__RequestVerificationToken']").eq(0).val();
			var model = {};
			model.totalList = totalList;
			model.conferenceId = $("#hidConferenceId").val();
			$.post("@Url.Action(nameof(MeetingBookingController.Submit),
					nameof(MeetingBookingController).GetControllerName())",
				{
					"__RequestVerificationToken": token,
					"model": model,
				},
				function(data, textStatus, jqXHR) {
			  		if (data.result == "@ConstValues.AjaxFailResult") {
			  			common.showError(data.message);
			  			layer.close(loading);
			  		} else {
			  			common.showSuccess(data.message, true);
			  			setTimeout(function () {
			  				$(window.location).attr("href", "@Url.Action(nameof(ProfileHotelController.Index),nameof(ProfileHotelController).GetControllerName())");
			  			}, 2000);
			  		}
				}
			  );
		}
	}

	function selectCurrency() {
		var isValid = $("#chooseCurrencyForm").form("validate");
		if (isValid) {
			$("#hidCurrency").val($("#ddlCurrency").combobox("getValue"));
			$("#currencyWindow").window("close");
		}
	}

	function calculateNight(obj) {
		var lastIndex = obj.id.substr(obj.id.length - 1, 1)
		var checkinDate = $("#checkinDate" + lastIndex).combobox("getValue");
		var checkoutDate = $("#checkoutDate" + lastIndex).combobox("getValue");
		if (checkinDate != "" && checkoutDate != "") {
			if (checkoutDate > checkinDate) {
				var day1 = new Date(checkinDate);
				var day2 = new Date(checkoutDate);
				var count = ((day2 - day1) / (1000 * 60 * 60 * 24)).toString() ;
				if ((day2 - day1) / (1000 * 60 * 60 * 24) > 1) {
					$("span[id='totalNightCount" + lastIndex + "']").html(count + " " + "@Resources.Nights")
				} else {
					$("span[id='totalNightCount" + lastIndex + "']").html(count + " " + "@Resources.Night")
				}
			} else {
				$("span[id='totalNightCount" + lastIndex + "']").html("")
			}
		}
	}

	function getHotelTips(objId) {
		var lastIndex = objId.substr(objId.length - 1, 1)
		var roomId = $("#roomType" + lastIndex).combobox("getValue");
		var checkinDate = $("#checkinDate" + lastIndex).combobox("getValue");
		var checkoutDate = $("#checkoutDate"+lastIndex).combobox("getValue");
		var roomNumber = $("#roomNumber" + lastIndex).numberbox("getValue");
		var hotelId = $("#hotel"+lastIndex).combobox("getValue");
		var currency = $("#hidCurrency").val();

		if (roomId != "" && checkinDate != "" && checkoutDate != "" && roomNumber != "" && checkinDate <= checkoutDate) {
			var url = "@Url.Action(nameof(MeetingBookingController.GetHotelTips),
					nameof(MeetingBookingController).GetControllerName())" + "?roomId=" + roomId
					+ "&checkinDate=" + checkinDate + "&checkoutDate=" + checkoutDate + "&roomNumber=" + roomNumber + "&hotelId=" + hotelId
					+ "&currency=" + currency +"&conferenceId=" + $("#hidConferenceId").val();
			$.post(url, $("#frmDetail").serialize(), function (data, textStatus, jqXHR) {
				$("span[id='leftRoomName"+lastIndex+"']").html(data.data.roomType)
				$("span[id='leftRoomCount"+lastIndex+"']").html(data.data.leftRoomCount)
				var dateList = data.data.checkinDateList;
				var couldList = data.data.couldBookList;
				$("#leftRoomDetail" + lastIndex).empty();
				var appendText = "<div style='margin-top: 5px;display:inline-block;'>"
				for (var i = 0; i < dateList.length; i++) {
					if (couldList[i] == true) {
						appendText += "<div style='width:68px;float:left'><span style='width:40px;height:22px;line-height:22px;border-radius:4px;background:#CC353D;display:inline-block;color:#fff'>" + dateList[i] + "</span></div>"
					} else {
						appendText += "<div style='width:68px;float:left'><span style='color:#CBCBCB'>" + dateList[i] + "</span></div>"
					}
				}
				appendText += "</div>"
				$("#leftRoomDetail" + lastIndex).append(appendText);
				document.getElementById("tips"+lastIndex).style.display = "";

				var number = parseInt(roomNumber);
				var nameDivCount = document.getElementsByName("nameInput" + lastIndex).length / 2; //获取现在又多少个nameDiv
				if (nameDivCount < number) {
					for (var i = nameDivCount; i < number; i++) {
						var tempNum = (i + 1).toString();
						$("#nameTd" + lastIndex).append("<div style='margin-top:20px;' id='nameDiv" + lastIndex + "_" + i.toString() + "'>"
							+ "<span>@Resources.Room" + tempNum + "：</span>"
							+ "<span style='margin-left:10px'><input id='name" + lastIndex + "_" + i.toString() + "_1" + "'  name='nameInput" + lastIndex + "' style='width:150px;height:27px' class='easyui-textbox' data-options='required:true'></span>"
							+ "<span style='margin-left:10px'><input  id='name" + lastIndex + "_" + i.toString() + "_2" + "' name='nameInput" + lastIndex + "' style='width:150px;height:27px;margin-left:5px' class='easyui-textbox' data-options='required:false'></span>"
						+ "</div>");

						$("#name" + lastIndex + "_" + i.toString() + "_1").textbox({ });
						$("#name" + lastIndex + "_" + i.toString() + "_2").textbox({ });
					}
				} else if (number < nameDivCount) {
					for (var i = number; i < nameDivCount; i++) {
						$("#nameDiv" + lastIndex + "_" + i.toString()).remove();
					}
				}

				var tempFlag = $('#needCombine' + lastIndex).is(':checked'); //获取原先是否拼房
				$("#needCombineDiv" + lastIndex).remove()
				$("#nameTd" + lastIndex).append("<div style='margin-top:7px;margin-bottom:40px' id='needCombineDiv" + lastIndex + "'>"
							+"<input id='needCombine"+lastIndex+"' type='checkbox' style='position:relative;top:7px;'>"
							+ "<span id='combineText" + lastIndex + "'>@Resources.NeedCombine</span>"
						+ "</div>");
				if (tempFlag) {
					$('#needCombine'+lastIndex).attr("checked",'checked');
				}
				if (data.data.roomBedCount == '1') {
					$("#needCombine" + lastIndex).hide()
					$("span[id='combineText" + lastIndex + "']").html("");
				}
				countTotalPrice();

				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
				}
			})
		} else if (roomId != "" && checkinDate != "" && checkoutDate != "" && roomNumber != "" && checkinDate > checkoutDate) {
			common.showError("@Resources.MsgChooseRightDate");
			document.getElementById("tips" + lastIndex).style.display = "none";
			countTotalPrice();
		}
	}

	function hotelContinueBooking() {
		var isValid = $("#booking").form("validate");
		var hotelCount = $("#hidHotelCount").val();
		var index = (parseInt(hotelCount) + 1 ).toString();
		if (isValid) {
			$("#booking").append("<table class='booking' id='booking"+index+"'>"
				+ "<tr>"
					+ "<td style='width:35%;text-align:right'>@Resources.HotelName：</td>"
					+ "<td><input id='hotel"+index+"' name='hotel' class='easyui-combobox' style='height:27px; width:500px' data-options='required:true'></td>"
				+ "</tr>"
				+ "<tr>"
					+ "<td>@Resources.RoomType：</td>"
					+ "<td>"
					    + "<input id='roomType"+index+"' name='roomType' class='easyui-combobox' style='height:27px; width:150px' data-options='required:true'>"
					    + "<span style='margin-left:20px'>@Resources.Price：</span>"
					    + "<span style='margin-left:20px' id='roomPrice" + index + "'></span>"
					    + "<input type='hidden' id='hidPrice" + index + "'>"
					+ "</td>"
				+ "</tr>"
				+ "<tr>"
					+ "<td>@Resources.CheckinDate：</td>"
					+ "<td>"
					    + "<input id='checkinDate" + index + "' name='checkinDate' style='width:150px;height:27px' class='easyui-combobox' data-options='editable:false,required:true' >"
					    + "<span style='margin-left:20px'>@Resources.CheckoutDate：</span>"
					    + "<input id='checkoutDate" + index + "' name='checkoutDate' style='width:150px;height:27px' class='easyui-combobox' data-options='editable:false,required:true' >"
					    + "<span style='margin-left:20px;width:60px;display: inline-block' id='totalNightCount" + index + "'></span>"
					    + "<span style='margin-left:20px'>@Resources.RoomNumber：</span>"
					    + "<input id='roomNumber" + index + "' name='roomNumber' style='width:50px;height:27px' class='easyui-numberbox' data-options='required:true,min:0,precision:0' >"
					+ "</td>"
				+ "</tr>"
				+ "<tr id='tips" + index + "' style='display:none'>"
					+ "<td colspan='2' >"
						+"<div id='tipsDiv'>"
							+ "<table style='border:#CEDDEF solid 1px; width:730px ;max-width:730px; margin-left:250px'>"
								+ "<tr>"
									+ "<td align='center' style='width:15%;text-align:center'>@Resources.RoomType</td>"
									+ "<td align='center' style='width:15%;text-align:center'>@Resources.LeftRoomCount</td>"
									+ "<td align='center' style='width:65%;text-align:center'>@Resources.ScheduleDate</td>"
								+ "</tr>"
								+ "<tr style='height:2px;'>"
									+ "<td align='center'  colspan='3' style='padding:0px;line-height:1px;margin:0;'><div style='width:95%;height:1px;background:#C4C3C3;line-height:1px;padding:0;margin-left:15px;' ></div></td>"
								+ "</tr>"
								+ "<tr class='booking-line'>"
									+ "<td align='center' style='width:15%;text-align:center'><span id='leftRoomName" + index + "'></span></td>"
									+ "<td align='center' style='width:15%;text-align:center'><span id='leftRoomCount" + index + "'></span></td>"
									+ "<td align='center' style='width:65%'>"
										+ "<div id='leftRoomDetail" + index + "'>"
										+ "</div>"
									+ "</td>"
								+ "</tr>"
								+ "<tr style='height:2px;'>"
									+ "<td align='center'  colspan='3' style='padding:0px;line-height:1px;margin:0;'><div style='width:95%;height:1px;background:#C4C3C3;line-height:1px;padding:0;margin-left:15px;' ></div></td>"
								+ "</tr>"
								+ "<tr>"
									+ "<td align='center' style='text-align:left;padding-left: 20px;' colspan='3'>@Resources.KindlyReminder</td>"
								+ "</tr>"
							+"</table>"
						+"</div>"
					+"</td>"
				+"</tr>"
				+"<tr>"
					+"<td>@Resources.CheckInNumber：</td>"
					+ "<td><input id='checkInNumber" + index + "' name='checkInNumber' style='height:27px; width:50px' class='easyui-numberbox' data-options='required:true,min:0,precision:0'></td>"
				+"</tr>"
				+"<tr>"
					+"<td valign='top'>@Resources.CheckInName：</td>"
					+ "<td valign='top' >"
						+ "<span id='nameTd" + index + "'></span>"
					+"</td>"
				+"</tr>"
				+ "</table>"
				+ "<div class='clear'></div>"
			);

			$("#hotel"+index).combobox({
				url: "@Url.Action(nameof(UtilityController.GetHotel),
						nameof(UtilityController).GetControllerName())?conferenceId=" + "@Model.ConferenceId",
				valueField: "id",
				textField: "name",
				required: true,
				editable: false,
				panelHeight: "auto",
				onSelect: function (rec) {
					$("span[id='roomPrice"+index+"']").html("");
					document.getElementById("tips" + index + "").style.display = "none";
					$("#roomType" + index).combobox({
						url: "@Url.Action(nameof(UtilityController.GetDistinctRoom),
								nameof(UtilityController).GetControllerName())?hotelId=" + rec.id + "&currency=" + $("#hidCurrency").val(),
						valueField: "id",
						textField: "name",
						editable: false,
						panelHeight: "auto",
						onSelect: function (record) {
							if ($("#hidIsBenefit").val() == "True") {
								$("span[id='roomPrice" + index + "']").html(record.currency + " " + record.price2);
								$("#hidPrice" + index).val(record.price2)
							} else {
								$("span[id='roomPrice" + index + "']").html(record.currency + " " + record.price1);
								$("#hidPrice" + index).val(record.price1)
							}
							getHotelTips(this.id);
						}
					});
				}
			});

			$("#roomType" + index).combobox({});
			$("#checkinDate"+index).combobox({
				url: "@Url.Action(nameof(UtilityController.GetConferenceCheckinDate),
						nameof(UtilityController).GetControllerName())" + "?conferenceId=" + "@Model.ConferenceId",
				valueField: "id",
				textField: "id",
				required: true,
				editable: false,
				panelHeight: "auto",
				onSelect: function (rec) {
					getHotelTips(this.id);
					calculateNight(this);
					compareDate(this.id);
				}
			});
			$("#checkoutDate"+index).combobox({
				url: "@Url.Action(nameof(UtilityController.GetConferenceCheckinDate),
						nameof(UtilityController).GetControllerName())" + "?conferenceId=" + "@Model.ConferenceId",
				valueField: "id",
				textField: "id",
				required: true,
				editable: false,
				panelHeight: "auto",
				onSelect: function (rec) {
					getHotelTips(this.id);
					calculateNight(this);
					compareDate(this.id);
				}
			});
			$("#roomNumber"+index).textbox({});
			$("input", $("#roomNumber" + index).next("span")).blur(function () {
				getHotelTips("roomNumber" + index)
			});
			$("#checkInNumber" + index).numberbox({});
			$("#checkInNumber" + index).next("span").children().first().blur(function () {
				compareCheckInNumber(index)
			});

			$("#hidHotelCount").val(index)
			$("#hotelCancelBtn").show();
		}
	}

	function hotelCancelBooking() {
		var hotelCount = $("#hidHotelCount").val();
		var index = parseInt(hotelCount);
		if (index > 0) {
			$("#booking" + hotelCount).remove();
			$("#hidHotelCount").val((index - 1).toString());
			if (index - 1 <= 0) {
				$("#hotelCancelBtn").hide();
			}
		}
		countTotalPrice();
	}

	function countTotalPrice() {
		var temp = parseInt($("#hidHotelCount").val());
		var hotelTotalFee = 0.00;
		for (var i = 0; i <= temp; i++) {
			if ($("#hidPrice" + i).val() != "" && $("#roomNumber" + i).numberbox("getValue") != "") {
				var checkinDate = $("#checkinDate" + i).combobox("getValue");
				var checkoutDate = $("#checkoutDate" + i).combobox("getValue");
				if (checkinDate < checkoutDate) {
					var aDate, oDate1, oDate2, iDays;
					aDate = checkoutDate.split("-");
					oDate1 = new Date(aDate[1] + "-" + aDate[2] + "-" + aDate[0]);  //转换为yyyy-MM-dd格式
					aDate = checkinDate.split("-");
					oDate2 = new Date(aDate[1] + "-" + aDate[2] + "-" + aDate[0]);
					iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数

					var price = parseFloat($("#hidPrice" + i).val()) * parseInt($("#roomNumber" + i).numberbox("getValue")) * iDays;
					hotelTotalFee += price;
				}
			}
		};
		$("span[id='hotelTotalFee']").html($("#hidCurrency").val() + " " + hotelTotalFee);
	}

	function goBack() {
		window.location.href = "@Url.Action(nameof(MeetingListController.Index),nameof(MeetingListController).GetControllerName())";
	}

	function goTrafficBooking() {
		$("#hotelBooking").hide();
		$("#trafficBooking").show()
	}

	function goHotelBooking() {
		$("#hotelBooking").show();
		$("#trafficBooking").hide()
	}

	function selectReceiving(obj) {
		var lastIndex = obj.id.substr(obj.id.length - 1, 1)
		var checkbox = document.getElementById("receivingCheckBox" + lastIndex)
		if (checkbox.checked) {
			$("#arrivalDate" + lastIndex).datetimebox({
				required: true,
				disabled: false
			});
			$("#arrivalNumber" + lastIndex).textbox({
				required: true,
				disabled: false
			});
			$("#arrivalName" + lastIndex).combobox({
				required: true,
				disabled: false
			});
			$("#arrivalName" + lastIndex).combobox({
				url: "@Url.Action(nameof(MeetingBookingController.GetReceivingTrafficName),
						nameof(MeetingBookingController).GetControllerName())"
						+ "?conferenceId=" + "@Model.ConferenceId"
						+"&currency="+$("#hidCurrency").val(),
				valueField: "id",
				textField: "name",
				required: true,
				editable: false,
				panelHeight: "auto",
				onSelect: function (rec) {
					if (rec.currency == "@ConstValues.Currency.美元") {
						$("span[id='arrivalPrice"+lastIndex+"']").html(rec.price + " " + "@Resources.DollarPerTime");
					} else {
						$("span[id='arrivalPrice"+lastIndex+"']").html(rec.price + " " + "@Resources.RmbPerTime");
					}
					$("#hidArrivalPrice" + lastIndex).val(rec.price)
					countTrafficTotalPrice();
				}
			});
		} else {
			$("#arrivalDate" + lastIndex).datetimebox("setValue", "");
			$("#arrivalDate" + lastIndex).datetimebox({
				required: false,
				disabled: true
			});
			$("#arrivalNumber" + lastIndex).textbox("setValue", "");
			$("#arrivalNumber" + lastIndex).textbox({
				required: false,
				disabled: true
			});
			$("#arrivalName" + lastIndex).combobox("setValue", "");
			$("#arrivalName" + lastIndex).combobox({
				required: false,
				disabled: true
			});
			$("span[id='arrivalPrice"+lastIndex+"']").html("");
			$("#hidArrivalPrice" + lastIndex).val("");
			countTrafficTotalPrice();
		}
	}

	function selectDelivery(obj) {
		var lastIndex = obj.id.substr(obj.id.length - 1, 1)
		var checkbox = document.getElementById("deliveryCheckBox" + lastIndex)
		if (checkbox.checked) {
			$("#deliveryDate" + lastIndex).datetimebox({
				required:true,
				disabled: false
			});
			$("#deliveryNumber" + lastIndex).textbox({
				required: true,
				disabled: false
			});
			$("#deliveryName" + lastIndex).combobox({
				required: true,
				disabled: false
			});
			$("#deliveryName" + lastIndex).combobox({
				url: "@Url.Action(nameof(MeetingBookingController.GetDeliveryTrafficName),
						nameof(MeetingBookingController).GetControllerName())"
						+ "?conferenceId=" + "@Model.ConferenceId"
						+"&currency="+$("#hidCurrency").val(),
				valueField: "id",
				textField: "name",
				required: true,
				editable: false,
				panelHeight: "auto",
				onSelect: function (rec) {
					if (rec.currency == "@ConstValues.Currency.美元") {
						$("span[id='deliveryPrice" + lastIndex + "']").html(rec.price + " " + "@Resources.DollarPerTime");
					} else {
						$("span[id='deliveryPrice" + lastIndex + "']").html(rec.price + " " + "@Resources.RmbPerTime");
					}
					$("#hidDeliveryPrice" + lastIndex).val(rec.price);
					countTrafficTotalPrice();
				}
			});
		} else {
			$("#deliveryDate" + lastIndex).datetimebox("setValue", "");
			$("#deliveryDate" + lastIndex).datetimebox({
				required: false,
				disabled: true
			});
			$("#deliveryNumber" + lastIndex).textbox("setValue", "");
			$("#deliveryNumber" + lastIndex).textbox({
				required: false,
				disabled: true
			});
			$("#deliveryName" + lastIndex).combobox("setValue", "");
			$("#deliveryName" + lastIndex).combobox({
				required: false,
				disabled: true
			});
			$("span[id='deliveryPrice" + lastIndex + "']").html("");
			$("#hidDeliveryPrice" + lastIndex).val("");
			countTrafficTotalPrice();
		}
	}

	function countTrafficTotalPrice() {
		var trafficCount = $("#hidTrafficCount").val();
		var totalPrice = 0.00;
		for (var i = 0; i <= parseInt(trafficCount) ; i++) {
			var arrivalPrice = $("#hidArrivalPrice" + i ).val();
			var deliveryPrice = $("#hidDeliveryPrice" + i).val();
			if (arrivalPrice != "") {
				totalPrice += parseFloat(arrivalPrice)
			}
			if (deliveryPrice != "") {
				totalPrice += parseFloat(deliveryPrice)
			}
		}
		if (totalPrice > 0) {
			if ($("#hidCurrency").val() == "@ConstValues.Currency.美元") {
				$("span[id='trafficTotalFee']").html(totalPrice + " " + "@Resources.Dollar");
			} else {
				$("span[id='trafficTotalFee']").html(totalPrice + " " + "@Resources.Yuan");
			}
		} else {
			$("span[id='trafficTotalFee']").html("");
		}
	}

	function doTrafficBooking() {
		var isValid = $("#trafficForm").form("validate");
		var isValid2 = $("#trafficContactForm").form("validate");
		var trafficCount = $("#hidTrafficCount").val();
		var index = (parseInt(trafficCount) + 1).toString();
		if (isValid && isValid2) {
			var loading = layer.load(0, {
				shade: [0.4, "#fff"]
			});
			var istrue = false;
			var list = [];
			for (var i = 0; i <= parseInt(trafficCount) ; i++) {
				var isChooseReceiving = $("#receivingCheckBox"+i).prop("checked") ? true : false;
				var isChooseDelivery = $("#deliveryCheckBox"+i).prop("checked") ? true : false;

				if (isChooseReceiving) {
					var model = {};
					model.isChooseReceiving = isChooseReceiving;
					model.flightDate = $("#arrivalDate" + i).datetimebox("getValue");
					model.flightNum = $("#arrivalNumber" + i).textbox("getValue");
					model.trafficId = $("#arrivalName" + i).combobox("getValue");
					model.remark = $("#trafficRemark").textbox("getValue");
					model.currency = $("#hidCurrency").val();
					model.contactName = $("#trafficContactName").textbox("getValue");
					model.contactMobile = $("#trafficContactMobile").textbox("getValue");
					model.contactMail = $("#trafficContactMail").textbox("getValue");
					model.trafficType = "@ConstValues.TrafficType.接机";
					model.totalFee = $("#trafficTotalFee").html();
					model.sequence = i;
					list.push(model);
				}
				if (isChooseDelivery) {
					var model = {};
					model.isChooseDelivery = isChooseDelivery;
					model.flightDate = $("#deliveryDate" + i).datetimebox("getValue");
					model.flightNum = $("#deliveryNumber" + i).textbox("getValue");
					model.trafficId = $("#deliveryName" + i).combobox("getValue");
					model.remark = $("#trafficRemark").textbox("getValue");
					model.currency = $("#hidCurrency").val();
					model.contactName = $("#trafficContactName").textbox("getValue");
					model.contactMobile = $("#trafficContactMobile").textbox("getValue");
					model.contactMail = $("#trafficContactMail").textbox("getValue");
					model.trafficType = "@ConstValues.TrafficType.送机";
					model.totalFee = $("#trafficTotalFee").html();
					model.sequence = i;
					list.push(model);
				}
			}

			if (list.length == 0) {
				layer.close(loading);
				return;
			}

			var token = $("#trafficForm").find("input[name='__RequestVerificationToken']").eq(0).val();
			var model = {};
			model.trafficList = list;
			model.conferenceId = $("#hidConferenceId").val();
			$.post("@Url.Action(nameof(MeetingBookingController.BookTrafficSubmit),
					nameof(MeetingBookingController).GetControllerName())",
				{
			  		"__RequestVerificationToken": token,
			  		"model": model,
				},
				function (data, textStatus, jqXHR) {
			  		if (data.result == "@ConstValues.AjaxFailResult") {
			  			common.showError(data.message);
			  			layer.close(loading);
			  		} else {
			  			common.showSuccess(data.message, true);
			  			setTimeout(function () {
			  				$(window.location).attr('href', '@Url.Action(nameof(ProfileTrafficController.Index),nameof(ProfileTrafficController).GetControllerName())');
			  			}, 2000);
			  		}
				}
			  );
		}
	}

	function trafficContinueBooking() {
		var isValid = $("#trafficForm").form("validate");
		var trafficCount = $("#hidTrafficCount").val();
		var index = (parseInt(trafficCount) + 1 ).toString();
		if (isValid) {
			if (trafficCount != "-1") {
				var isChooseReceiving = $("#receivingCheckBox" + trafficCount).prop("checked") ? true : false;
				var isChooseDelivery = $("#deliveryCheckBox" + trafficCount).prop("checked") ? true : false;
				if (!isChooseReceiving && !isChooseDelivery) {
					return;
				}
			}
			$("#trafficDiv").append("<div id='traffic" + index + "'>"
				  +"<table style='margin-bottom: 30px;width:600px;margin:0 auto'>"
				  + "<tr>"
				       + "<td valign='top' rowspan='5' style='width:13px;padding-top:20px'><input type = 'checkbox' id='receivingCheckBox" + index + "' name='receivingCheckBox' onchange='selectReceiving(this)' style='margin-top:5px'></td>"
				       + "<td style='padding-left :30px;padding-top:24px;font-size:16px;font-weight:bold'> @Resources.ReceivingService</td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.ArrivalDate：<input id='arrivalDate" + index + "' name='arrivalDate' style='width:400px;height:27px' class='easyui-datetimebox' data-options='editable:false' disabled></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.FlightTrainNumber：<input id='arrivalNumber" + index + "' name ='arrivalNumber' style='width:400px;height:27px'  class='easyui-textbox' data-options='' disabled></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.TrafficName：<input id='arrivalName" + index + "' name ='arrivalName' style='width:400px;height:27px'  class='easyui-combobox' data-options='' disabled></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.Price：<span id='arrivalPrice" + index + "'></span><input type='hidden' id='hidArrivalPrice" + index + "'/></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td valign='top' rowspan='5' style='width:13px;padding-top:20px'><input type = 'checkbox' id='deliveryCheckBox" + index + "' name='deliveryCheckBox' onchange='selectDelivery(this)' style='margin-top:5px'></td>"
				       + "<td style='padding-left :30px;padding-top:24px;font-size:16px;font-weight:bold'> @Resources.DeliveryService</td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.DepartureTime：<input id='deliveryDate" + index + "' name='deliveryDate' style='width:400px;height:27px' class='easyui-datetimebox' data-options='editable:false' disabled></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.FlightTrainNumber：<input id='deliveryNumber" + index + "' name ='deliveryNumber' style='width:400px;height:27px'  class='easyui-textbox' data-options='' disabled></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.TrafficName：<input id='deliveryName" + index + "' name ='deliveryName' style='width:400px;height:27px'  class='easyui-combobox' data-options='' disabled></td>"
				  + "</tr>"
				  + "<tr>"
				       + "<td style='padding-left :30px;padding-top:10px'>@Resources.Price：<span id='deliveryPrice" + index + "'></span><input type='hidden' id='hidDeliveryPrice" + index + "' /></td>"
				  + "</tr>"
				  + "</table>"
				  +"</div>"
			);
			$("#arrivalDate" + index).datetimebox({
				showSeconds: false
			});
			$("#arrivalNumber" + index).textbox({});
			$("#arrivalName" + index).combobox({});
			$("#deliveryDate" + index).datetimebox({
				showSeconds: false
			});
			$("#deliveryNumber" + index).textbox({});
			$("#deliveryName" + index).combobox({});

			$("#hidTrafficCount").val(index)
			$("#trafficCancelBtn").show();
		}
	}

	function trafficCancelBooking() {
		var trafficCount = $("#hidTrafficCount").val();
		var index = parseInt(trafficCount);
		if (index > 0) {
			$("#traffic" + trafficCount).remove();
			$("#hidTrafficCount").val((index - 1).toString());
			if (index - 1 <= 0) {
				$("#trafficCancelBtn").hide();
			}
		}
		countTrafficTotalPrice();
	}

	function compareDate(objId) {
		var lastIndex = objId.substr(objId.length - 1, 1)
		if ($("#checkinDate" + lastIndex).combobox("getValue") != "" && $("#checkoutDate" + lastIndex).combobox("getValue") &&  $("#checkinDate" + lastIndex).combobox("getValue") >= $("#checkoutDate" + lastIndex).combobox("getValue")) {
			common.showError("@Resources.MsgChooseRightDate");
			return;
		}
	}

	function compareCheckInNumber(lastIndex) {
		var roomNumber = $("#roomNumber" + lastIndex).numberbox("getValue");
		var checkInNumber = $("#checkInNumber" + lastIndex).numberbox("getValue");
		if (parseInt(checkInNumber) > parseInt(roomNumber) * 2) {
			common.showError("@Resources.MsgTooMuchCheckin");
			return;
		}
	}
</script>
}